<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<title>GT pro钱包</title>
		<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
		<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css">
		<link rel="stylesheet" href="bower_components/font-awesome/css/font-awesome.min.css">
		<link rel="stylesheet" href="bower_components/Ionicons/css/ionicons.min.css">
		<link rel="stylesheet" href="bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css">
		<link rel="stylesheet" href="dist/css/AdminLTE.min.css">
		<link rel="stylesheet" href="dist/css/skins/skin-blue.min.css">
		<link rel="stylesheet" href="css/fr_style.css">
		<link rel="stylesheet" href="css/style.css">
		<link rel="stylesheet" href="css/card.css">
		<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic">

		<link rel="stylesheet" href="bower_components/bootstrap-daterangepicker/daterangepicker.css">
		<link rel="stylesheet" href="bower_components/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
		<style>
			.dealSum{
				padding:15px 0;
				font-size:15px;
			}
			.rfloat{
				float: right;
				margin-right:20px;
			}
			.copyWarp{
				position: relative;
				width: 200px;
				line-height: 34px;
				padding-right: 90px;
			}
			.copy{
				position: absolute;
			}
		</style>
	</head>

	<body class="hold-transition skin-blue sidebar-mini">
		<div class="wrapper">
			<div class="content-wrapper">
				<section class="content-header">
					<ol class="breadcrumb">
						<li>
							<a href="#"><i class="fa fa-dashboard"></i>用户管理</a>
						</li>
						<li class="active">交易记录</li>
					</ol>
				</section>
				<section class="content">
					<div class="box">
						<div class="box-header with-border">
							交易记录列表
						</div>
						<div class="box-body">
							<div class="buyu_search_group">
								<div class="row" style="margin-bottom:10px;">
									<div class="col-xs-12 col-sm-6 col-lg-3">
										<div class="input-group margin">
											<div class="input-group-btn">
												<button type="button" class="btn btn-default" aria-expanded="false">币种</button>
											</div>
											<select type="text" class="form-control" id="coin_id"></select>
										</div>
									</div>
									<div class="col-xs-12 col-sm-6 col-lg-3">
										<div class="input-group margin">
											<div class="input-group-btn">
												<button type="button" class="btn btn-default" aria-expanded="false">用户id</button>
											</div>
											<input type="text" class="form-control" id="user_id">
										</div>
									</div>
									<div class="col-xs-12 col-sm-6 col-lg-3">
										<div class="input-group margin">
											<div class="input-group-btn">
												<button type="button" class="btn btn-default" aria-expanded="false">搜索地址</button>
											</div>
											<input type="text" class="form-control" id="search_address">
										</div>
									</div>
									<div class="col-xs-12 col-sm-6 col-lg-3">
										<div class="input-group margin">
											<div class="input-group-btn">
												<button type="button" class="btn btn-default" aria-expanded="false">发起时间</button>
											</div>
											<!-- /btn-group -->
											<input type="text" class="form-control" id="select_time" autocomplete="off">
											<div class="input-group-addon clearBtns" onclick="clearRangeTime(this)">x</div>
										</div>
									</div>
									<div class="col-xs-12 col-sm-6 col-lg-3">
										<div class="input-group margin">
											<div class="input-group-btn">
												<button type="button" class="btn btn-default" aria-expanded="false">状态</button>
											</div>
											<select type="text" class="form-control" id="status">
												<option value="">请选择类型</option>
												<option value="0">进行中</option>
												<option value="1">成功</option>
												<option value="2">失败</option>
												<option value="3">等待审核</option>
												<option value="4">审核中</option>
											</select>
										</div>
									</div>
									<div class="col-xs-12 col-sm-6 col-lg-3">
										<div class="input-group margin">
											<div class="input-group-btn">
												<button type="button" class="btn btn-default" aria-expanded="false">交易类型</button>
											</div>
											<select type="text" class="form-control dealTyle" id="type">
												<option value="">请选择类型</option>
											</select>
										</div>
									</div>
									<div class="col-xs-12 col-sm-6 col-lg-3">
										<button type="button" class="btn bg-primary margin" onclick="search()"><i class="fa fa-search" ></i>&nbsp;搜索</button>
										<button type="button" class="btn bg-primary margin" onclick="reset()"><i class="fa fa-trash" ></i>&nbsp;重置</button>
									</div>
									
								</div>
							</div>
						</div>
						<div class="row">
							<div class="col-xs-12">
								<!-- /.box-header -->
								<div class="box-body">
									<table id="example" class="display nowrap table table-bordered table-striped" style="width:100%;">
										<thead>
											<tr>
												<th>ID</th>
												<th>发起用户</th>
												<th>收款用户</th>
												<th>发起地址</th>
												<th>收款地址</th>
												<th>数量</th>
												<th>手续费</th>
												<th>结束时间</th>
												<th>备注</th>
												<th>状态</th>
											</tr>
										</thead>
										<tbody></tbody>
									</table>
									<div class="dealSum clearfix" >
										<div style="float:left">
											转入：<span id="sum_in">--</span>
										</div>
										<div style="float:left;margin-left:20px;">
											转出：<span id="sum_out">--</span>
										</div>
									</div>
									
								</div>
							</div>
						</div>
					</div>
				</section>
			</div>
		</div>
		
		<script src="bower_components/jquery/dist/jquery.min.js"></script>
		<script src="bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
		<script src="bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
		<script src="bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>

		<script src="bower_components/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
		<script src="bower_components/moment/min/moment.min.js"></script>
		<script src="bower_components/bootstrap-daterangepicker/daterangepicker.js"></script>
		<script src="js/clipboard.min.js"></script>
		<script src="dist/js/adminlte.min.js"></script>
		<script src="js/argument.js"></script>
		<script src="js/fun.js"></script>
		<script src="js/nav.js"></script>
		<script src="js/pop.js"></script>
		<script src="js/getList.js"></script>
		<script type="text/javascript">
			var typeJson = {
				0:'转入转出',
				1:'转入', 
				2:'转出',
				3:'购买算力',  
				4:'算力产出', 
				5:'质押', 
				6:'解押', 
				7:'空投',
				8:'青铜奖励',   
				9:'白银奖励',  
				10:'黄金奖励',  
				11:'铂金奖励',  
				12:'砖石奖励',   
				13:'兑换扣除',   
				14:'兑换获得',	
			}
			$.each(typeJson,function(index,item){
				$('.dealTyle').append("<option value='"+index+"'>"+item+"</option>")
			})
			
			var table,tablePage;
			$.ajax({
				type: 'post',
				url: url + "Back_MainChainForCoin",
				contentType: "application/x-www-form-urlencoded",
				headers: {
					"auth-token": localStorage.getItem("wallet_token")
				},
				data: {
					data: JSON.stringify({
						page_num: 1
					})
				},
				dataType:'json',
				success: function(res) {
					console.log(res);
					if(res.status == 1000||res.status == 102) {
						ToLogin(res)
						return false;
					} else if(res.status != 1) {
						alert(res.error);
						return false;
					}
					$.each(res.data, function(index, item) {
						$("#coin_id").append("<option value='" + item.id + "'>" + item.name + "</option>");
					})
					if(GetRequest().coin_id){
						$("#coin_id").val(GetRequest().coin_id);
						$('#user_id').val(GetRequest().user_id)
					}
					table = tableRander();
				}
			})
			$('#select_time').daterangepicker({
				timePicker: true,
				timePicker24Hour: true,
				autoUpdateInput: false,
				locale: {
					format: "YYYY-MM-DD HH:mm"
				}
			})

			$('#login_time').daterangepicker({
				timePicker: true,
				timePicker24Hour: true,
				autoUpdateInput: false,
				locale: {
					format: "YYYY-MM-DD HH:mm"
				}
			})

			$('#endTime').datepicker({
				autoclose: true,
				format: 'yyyy-mm-dd',
			})
			function tableRander(){
				var table = $('#example').DataTable({
					'ordering': false,
					'lengthChange': false,
					'searching': false,
					'info': true,
					"processing": true,
					"serverSide": true,
					'scrollX':true,
					"ajax": {
						"type": 'post',
						"url": url + "Back_UserCoinHistory",
						'contentType': "application/x-www-form-urlencoded",
						"headers": {
							"auth-token": localStorage.getItem("wallet_token")
						},
						"data": function(d) {
							var dataType ={
								coin_id:{type:'string',value:$("#coin_id").val()},
								type:{type:'string',value:$("#type").val()},
								status:{type:'string',value:$("#status").val()},
								search_address:{type:'string',value:$("#search_address").val()},
								user_id:{type:'string',value:$("#user_id").val()},
								start_time:{type:'time',value:$("#select_time").val().substring(0, 16)},
								end_time:{type:'time',value:$("#select_time").val().substring(19, 35)}
							}
							var Json = renderData(dataType);
							Json.page_num = d.start / 10 + 1;
							tablePage = d.start / 10 + 1;
							var data={};
							data.data = JSON.stringify(Json);
							return data;
						},
						"dataFilter": function(data) {
							var datajson = eval('(' + data + ')');
							if(datajson.status == 1000||datajson.status == 102) {
								ToLogin(datajson)
								return false;
							} else if(datajson.status != 1) {
								alert(datajson.error);
								return false;
							}
							var json = {};
							if(datajson.data==null){
								json.recordsTotal = 0;
								json.recordsFiltered = 0;
								json.data = [];
								return JSON.stringify(json);
							}else{
								if(tablePage == 1){
									$('#sum_out').html(datajson.data.sum_out);
									$('#sum_in').html(datajson.data.sum_in);
								}
								json.recordsTotal = datajson.data.total;
								json.recordsFiltered = datajson.data.total;
								json.data = datajson.data.data_list;
								return JSON.stringify(json);
							}
						}
					},
					"columns": [{
							data: 'id'
						},
						{
							data:null,render:function(data){
								return '<a href="user_list.html?user_id='+data.from_user_id+'">'+data.from_user_id+'</a>'	
							}
						},
						{
							data:null,render:function(data){
								return '<a href="user_list.html?user_id='+data.to_user_id+'">'+data.to_user_id+'</a>'	
							}
						},
						{
							data:null,render:function(data){
								
								if(data.from_address){
									return '<div class="copyWarp">\
									<div class="lfloat toolong from_address'+data.id+'" style="width:100px;">'+data.from_address+'</div><button type="button" class="btn btn-primary rfloat copy" data-clipboard-action="copy" data-clipboard-target=".from_address'+data.id+'"+>&nbsp;复制</button></div>';
								}else{
									return '';
								}
							}
						},
						{
							data:null,render:function(data){
								if(data.to_address){
									return '<div class="copyWarp">\
									<div class="lfloat toolong to_address'+data.id+'" style="width:100px;">'+data.to_address+'</div><button type="button" class="btn btn-primary rfloat copy" data-clipboard-action="copy" data-clipboard-target=".to_address'+data.id+'"+>&nbsp;复制</button></div>';
									
									//return data.to_address.substr(0,10)+"..."+data.to_address.substr(data.to_address.length-8,data.to_address.length)
								}else{
									return '';
								}
								
							}
						},
						{
							data: null,render:function(data){
								return data.number+"&nbsp;"+"<span style='font-size:12px;'>"+data.coin_name+"</span>"
							}
						},
						{
							data: null,render:function(data){
								return data.charge_num_string+"&nbsp;"+"<span style='font-size:12px;'>"+data.charge_coin_name+"</span>"
							}
						},
						{
							data: 'end_time'
						},
						{
							data: 'remark'
						},
						{
						data: null,
						render: function(data) {
												//：0：进行中   1：成功    2：失败   3：等待转账   4：等待审核
							var dataList = {
								0:{name:'进行中',color:'info'},
								1:{name:'成功',color:'success'},
								2:{name:'失败',color:'danger'},
								3:{name:'等待转账',color:'info'},
								4:{name:'等待审核',color:'info'},
							}
							return '<div class="fr_status fr_'+dataList[data.status].color+'">'+dataList[data.status].name+'</div>'
						}
					}]
				})
				return table;
			}
			
		</script>
		<script type="text/javascript">
			// 添加
			var clipboard = new ClipboardJS('.copy');

			clipboard.on('success', function(e) {
			    move('success','复制成功！');
			});
			
			clipboard.on('error', function(e) {
			   move('danger','复制失败！');
			});
			
			function addSave() {
				if($("#addUserModal [name=account]").val()==""){
					alert("昵称不能为空！")
					return false;
				}
				if($("#addUserModal [name=loginPassword]").val()==""){
					alert("密码不能为空！")
					return false;
				}
				if($("#addUserModal [name=mobile]").val()==""){
					alert("手机号不能为空！")
					return false;
				}
				$.ajax({
					type: 'post',
					url: url + "account",
					"headers": {
						"token": localStorage.getItem("buyu_token")
					},
					"contentType": "application/json",
					data: JSON.stringify({
						loginPassword: $("#addUserModal [name=loginPassword]").val(),
						account: $("#addUserModal [name=account]").val(),
						mobile: $("#addUserModal [name=mobile]").val(),
					}),
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.error);
							return false;
						}
						$("#addUserModal").modal("hide");
						move("success", res.error);
						table.draw(false);
					}
				})
			}

			function addUser() {
				var addJson = {
					name: "addUser",
					title: "添加用户",
					arg: {
						"account": {
							name: "昵称",
							type: "text"
						},
						"loginPassword": {
							name: "密码",
							type: "text"
						},
						"mobile": {
							name: "手机号",
							type: "text",
						}
					}, //参数
				};
				addModal(addJson, 'addSave');
			}

			// 冻结
			function freezeSave() {
				$.ajax({
					type: "put",
					"headers": {
						"token": localStorage.getItem("buyu_token")
					},
					url: url + "account/" + $("#freezeUserModal [name=id]").val(),
					contentType: "application/json",
					data: JSON.stringify({ //昵称
						state: 2
					}),
					dataType: "json",
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.error);
							return false;
						}
						$("#freezeUserModal").modal("hide");
						move("success", res.error);
						table.draw(false);
					}
				})
			}

			function freeze(_this) {
				var data = JSON.parse($(_this).siblings('input').val())
				var deleteJson = {
					name: "freezeUser",
					title: "冻结昵称",
					arg: {
						id: data.Id,
						name: data.Account
					}
				};
				deleteModal(deleteJson, 'freezeSave');
			}

			// 解冻
			function unFreezeSave() {
				$.ajax({
					type: "put",
					"headers": {
						"token": localStorage.getItem("buyu_token")
					},
					url: url + "account/" + $("#unFreezeUserModal [name=id]").val(),
					contentType: "application/json",
					data: JSON.stringify({ //昵称
						state: 11
					}),
					dataType: "json",
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.error);
							return false;
						}
						$("#unFreezeUserModal").modal("hide");
						move("success", res.error);
						table.draw(false);
					}
				})
			}

			function unFreeze(_this) {
				var data = JSON.parse($(_this).siblings('input').val())
				var deleteJson = {
					name: "unFreezeUser",
					title: "解冻昵称",
					arg: {
						id: data.Id,
						name: data.Account
					}
				};
				deleteModal(deleteJson, 'unFreezeSave');
			}

			// 拉黑
			function toBlackSave() {
				$.ajax({
					type: "put",
					"headers": {
						"token": localStorage.getItem("buyu_token")
					},
					url: url + "account/" + $("#toBlackModal [name=id]").val(),
					contentType: "application/json",
					data: JSON.stringify({ //昵称
						state: 3,
						endTime: $("#endTime").val(),
						opPw:$("#toBlackModal [name=OPassword]").val(),
						//拉黑时间
					}),
					dataType: "json",
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.error);
							return false;
						}
						$("#toBlackModal").modal("hide");
						move("success", res.error);
						table.draw(false);
					}
				})
			}

			function toBlack(_this) {
				console.log(111);
				var data = JSON.parse($(_this).siblings('input').val())

				$("#toBlackModal [name=id]").val(data.Id);
				$("#toBlackModal [name=name]").html(data.Account)
				$("#endTime").val("");
				$("#toBlackModal [name=OPassword]").val("");
				$("#toBlackModal").modal("show");
				
			}

			//移出黑名单
			function cancelBlackSave() {
				$.ajax({
					type: "put",
					"headers": {
						"token": localStorage.getItem("buyu_token")
					},
					url: url + "account/" + $("#cancelBlackModal [name=id]").val(),
					contentType: "application/json",
					data: JSON.stringify({ //昵称
						state: 1,
						opPw:$("#cancelBlackModal [name=OPassword]").val(),
					}),
					dataType: "json",
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.error);
							return false;
						}
						$("#cancelBlackModal").modal("hide");
						move("success", res.error);
						table.draw(false);
					}
				})
			}

			function cancelBlack(_this) {
				var data = JSON.parse($(_this).siblings('input').val())
				var deleteJson = {
					name: "cancelBlack",
					title: "移除黑名单",
					needPassword:true,
					arg: {
						id: data.Id,
						name: data.Account
					}
				};
				deleteModal(deleteJson, 'cancelBlackSave');
			}

			//充值金币
			function goldCoinSave() {
				$.ajax({
					type: "put",
					"headers": {
						"token": localStorage.getItem("buyu_token")
					},
					url: url + "account/" + $("#goldCoinModal [name=id]").val(),
					contentType: "application/json",
					data: JSON.stringify({ //昵称
						"bulletNum": Number($("#goldCoinModal [name=bulletNum]").val()),
						opPw:$("#goldCoinModal [name=opPw]").val()
					}),
					dataType: "json",
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.error);
							return false;
						}
						$("#goldCoinModal").modal("hide");
						move("success", "充值成功");
						table.draw(false);
					}
				})
			}

			function goldCoin(_this) {
				var data = JSON.parse($(_this).siblings('input').val())
				var editJson = {
					name: "goldCoin",
					title: "充值子弹",
					arg: {
						id: {
							type: "id",
							value: data.Id
						},
						bulletNum: {
							name: "充值子弹数",
							type: "text",
							value: ""
						},
						opPw: {
							name: "操作密码",
							type: "password",
							value: ""
						}
					}, //参数
				};
				editModal(editJson, 'goldCoinSave');
			}

			function setSuperSave() {
				//				if()
				$.ajax({
					type: 'put',
					"headers": {
						"token": localStorage.getItem("buyu_token")
					},
					url: url + 'account/' + $("#setSuperModal [name=id]").val(),
					data: JSON.stringify({
						isSuper: Number($("#setSuperModal [name=isSuper]").val()),
						opPw:$("#setSuperModal [name=OPassword]").val(),
					}),
					success: function(res) {
						if(res.status == 1000||res.status == 102) {
							ToLogin(res)
							return false;
						} else if(res.status != 1) {
							alert(res.error+":"+res.data);
							return false;
						}
						$("#setSuperModal").modal("hide");
						$("#setSuperModal").find("[name=OPassword]").val("")
						move("success", "修改成功");
						table.draw(false);
					}
				})
			}

			$("#example").on("click", ".isSuperSet", function() {
				$("#setSuperModal").find("[name=name]").text($(this).attr("data_Account"))
				$("#setSuperModal").find("[name=id]").val($(this).attr("data_Id"))
				
				if($(this).hasClass("active")) {
					$("#setSuperModal").find("[name=doSuper]").text("取消")
					
					$("#setSuperModal").find("[name=isSuper]").val(2)
				} else {
					$("#setSuperModal").find("[name=doSuper]").text("设置")
					$("#setSuperModal").find("[name=isSuper]").val(1)
				}
				$("#setSuperModal").modal("show");
			})

			function checkDetails(id) {
				window.location.href = 'user_details.html?user_id=' + id;
			}
		</script>
	</body>

</html>